package com.ztsoft.user.pojo.vo.dynamic;

import com.google.gson.Gson;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SearchItemVo implements Serializable {
    //搜索条件里面的
    private Map<String, Object> paramMap = new HashMap<>();
    //过滤条件
    private String condition;
    //高级搜索条件
    private List<Map<String, Object>> multiConditionList = new ArrayList<>();

    public SearchItemVo(Map<String, Object> map) {
        String advancedSearch = String.valueOf(map.get("advancedSearch"));
        this.condition = String.valueOf(map.get("condition"));
        map.remove("advancedSearch");
        map.remove("condition");
        if (advancedSearch != null && !advancedSearch.isEmpty()) {
            try {
                // 解密
                String decode = "{test : " + URLDecoder.decode(advancedSearch, "UTF-8") + "}";
                Gson gson = new Gson();
                Map<String, Object> map1;
                map1 = gson.fromJson(decode, map.getClass());

                List<Map<String, Object>> multiConditionList = (List<Map<String, Object>>) map1.get("test");

                this.multiConditionList = multiConditionList;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        this.setParamMap(map);
    }
}